/*
 * Copyright (c) 2016-2020, Chengdu RST technology co., ltd
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-12-15     shijiabao       the first version
 */
#ifndef APPLICATIONS_SPI_FLASH_BSP_SPI_FLASH_H_
#define APPLICATIONS_BSP_SPI_FLASH_H_

/* SPI 设备总线  */
#define SPI_BUS_NAME "spi1"
/* SPI设备名称 */
#define W25Q64_SPI_DEVICE_NAME "spi10"
/* SPI FLASH 块设备名称 */
#define W25Q64_BLOCK_DEVICE_NAME "W25Q64"
/* SPI FLASH ID */
#define W25Q64_FLASH_ID 0XEF4017
/* SPI设备句柄 */
struct rt_spi_device *spi_dev_w25q;

#define SPI_FLASH_PageSize              256
#define SPI_FLASH_PerWritePageSize      256

/* W25Q64 SPI FLASH 指令 */
#define W25X_WriteEnable              0x06
#define W25X_WriteDisable             0x04
#define W25X_ReadStatusReg            0x05
#define W25X_WriteStatusReg           0x01
#define W25X_ReadData                 0x03
#define W25X_FastReadData             0x0B
#define W25X_FastReadDual             0x3B
#define W25X_PageProgram              0x02
#define W25X_BlockErase               0xD8
#define W25X_SectorErase              0x20
#define W25X_ChipErase                0xC7
#define W25X_PowerDown                0xB9
#define W25X_ReleasePowerDown         0xAB
#define W25X_DeviceID                 0xAB
#define W25X_ManufactDeviceID         0x90
#define W25X_JedecDeviceID            0x9F

/* WIP(busy)标志，FLASH内部正在写入 */
#define WIP_Flag                  0x01
#define Dummy_Byte                0xFF

void spi_flash_init(void);
void spi_flash_buffer_write(uint8_t *pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);

#endif /* APPLICATIONS_SPI_FLASH_BSP_SPI_FLASH_H_ */
